let express = require('express')
let router = express.Router()
let uploadCtrl=require('../../controller/upload/upload')
// 登陆
// 1. 引入依赖
const multer = require('multer');

// 2. 引入工具
const path = require('path') 
const fs=require('fs')

// 3. multer的配置对象
let storage = multer.diskStorage({
    // 3.1 存储路径
    destination: function (req, file, cb) {
        cb(null,path.join(__dirname,'../..//public/imgs'))
    },
    //  3.2 存储名称
    filename: function (req, file, cb) {
        let type = file.mimetype.split('/node_modules')[1]
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
        // cb(null, file.fieldname + '-' + uniqueSuffix+'.'+type)
        cb(null, file.originalname)
    },
});

// 4. 添加配置
const multerConfig = multer({
    storage: storage,
});
router.post('/upload',multerConfig.single('file'),uploadCtrl.upload)
module.exports = router
